﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DDit.Component.Tools.weixin
{
    public class WxApiUrl
    {
        public readonly static string Token = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}";
        /// <summary>
        /// 获取用户列表 GET 
        /// </summary>
        public static readonly string UserList = "https://api.weixin.qq.com/cgi-bin/user/get?access_token={0}&next_openid={1}";

        /// <summary>
        /// 获取用户信息 GET 
        /// </summary>
        public static readonly string UserInfo = "https://api.weixin.qq.com/cgi-bin/user/info?access_token={0}&openid={1}&lang=zh_CN";
        /// <summary>
        /// 批量获取用户基本信息
        /// </summary>
        public static readonly string UserInfoList = "https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token={0}";
        /// <summary>
        /// 设置用户备注名
        /// POST数据例子：
        /// {
        /// "openid":"oDF3iY9ffA-hqb2vVvbr7qxf6A0Q",
        /// "remark":"pangzi"
        /// }
        /// </summary>
        public static readonly string RemarkInfo = "https://api.weixin.qq.com/cgi-bin/user/info/updateremark?access_token={0}";
        /// <summary>
        /// 创建标签{"tag" : {"name" : "广东"//标签名}}
        /// </summary>
        public static readonly string createTag = "https://api.weixin.qq.com/cgi-bin/tags/create?access_token={0}";
        /// <summary>
        /// 编辑标签
        /// </summary>
        public static readonly string updateTag = "https://api.weixin.qq.com/cgi-bin/tags/update?access_token={0}";
        /// <summary>
        /// 删除标签
        /// </summary>
        public static readonly string deleteTag = "https://api.weixin.qq.com/cgi-bin/tags/delete?access_token={0}";
        /// <summary>
        /// 获取公众号已创建的标签
        /// </summary>
        public static readonly string getTag = "https://api.weixin.qq.com/cgi-bin/tags/get?access_token={0}";
        /// <summary>
        /// 批量为用户打标签
        /// </summary>
        public static readonly string addUserTage = "https://api.weixin.qq.com/cgi-bin/tags/members/batchtagging?access_token={0}";
        /// <summary>
        /// 批量为用户取消标签
        /// </summary>
        public static readonly string delUserTage = "https://api.weixin.qq.com/cgi-bin/tags/members/batchuntagging?access_token={0}";
        /// <summary>
        /// 获取标签下粉丝列表
        /// </summary>
        public static readonly string GetTageUser = "https://api.weixin.qq.com/cgi-bin/user/tag/get?access_token={0}";
        /// <summary>
        /// 拉黑用户
        /// </summary>
        public static readonly string PullBlackUser = "https://api.weixin.qq.com/cgi-bin/tags/members/batchblacklist?access_token={0}";
        /// <summary>
        /// 取消拉黑用户
        /// </summary>
        public static readonly string CancelBlack = "https://api.weixin.qq.com/cgi-bin/tags/members/batchunblacklist?access_token={0}";
        /// <summary>
        /// 获取公众号的黑名单列表
        /// </summary>
        public static readonly string GetBlackUser = "https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token={0}";
        /// <summary>
        /// 对话图灵机器人
        /// </summary>
        /// <param name="p_strMessage"></param>
        /// <returns></returns>
        public static string ConnectTuLing(string p_strMessage)
        {
            string result = null;
            try
            {
                //注册码自己到网上注册去
                String APIKEY = "e1d8147624eb400081f2536b32665d4e";
                String _strMessage = p_strMessage;
                String INFO = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes(_strMessage));
                String getURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO;
                String bayb_q = HttpHelper.HttpGet(getURL, "");

                //解析json
                JsonReader reader = new JsonTextReader(new StringReader(bayb_q));
                while (reader.Read())
                {
                    //text中的内容才是你需要的
                    if (reader.Path == "text")
                    {
                        //结果赋值
                        result = reader.Value.ToString();
                    }
                }
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return result;
        }
    }
}
